﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using NLBS.Entity;
using System.Data;

namespace NLBS.Data
{
    public partial class AccessDataProvider : DbProvider
    {
        #region trackback

        public override IList<TrackBack> GetTrackBack()
        {
            DbCommand dbCommand = db.GetSqlStringCommand("select * from blog_Trackback");
            IList<TrackBack> lists = new List<TrackBack>();
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                while (dataReader.Read())
                {
                    TrackBack sm = CommonDataProvider.PopulateTrackBackFromIDataReader(dataReader);
                    lists.Add(sm);
                }
            }
            return lists;
        }

        public override void InsertTrackBack(TrackBack tb)
        {
            DbCommand dbCommand = db.GetSqlStringCommand("INSERT INTO [dbo].[blog_Trackback] ([log_id], [tb_url], [tb_title], [tb_blog], [tb_excerpt], [tb_time], [tb_ip]) VALUES (@log_id, @tb_url, @tb_title, @tb_blog, @tb_excerpt, @tb_time, @tb_ip)");
            db.AddInParameter(dbCommand, "log_id", DbType.Int32, tb.LogID);
            db.AddInParameter(dbCommand, "tb_url", DbType.String, tb.Url);
            db.AddInParameter(dbCommand, "tb_title", DbType.String, tb.Title);
            db.AddInParameter(dbCommand, "tb_blog", DbType.String, tb.BlogName);
            db.AddInParameter(dbCommand, "tb_excerpt", DbType.String, tb.Excerpt);
            db.AddInParameter(dbCommand, "tb_time", DbType.DateTime, tb.Time);
            db.AddInParameter(dbCommand, "tb_ip", DbType.String, tb.IP);
            db.ExecuteNonQuery(dbCommand);
        }

        public override TrackBack GetTrackBackByID(int id)
        {
            throw new NotImplementedException();
        }

        public override void UpdateTrackBack(TrackBack tb)
        {

        }

        public override IPagedCollection<TrackBack> GetTrackBackBySearch(int startIndex, int pageSize, string prefix)
        {
            throw new NotImplementedException();
        }

        public override TrackBack GetTrackBackByName(string title, string excerpt)
        {
            throw new NotImplementedException();
        }

        public override void DeleteTrackBack(int id)
        {
            DbCommand dbCommand = db.GetSqlStringCommand("delete from blog_trackback where tb_id=?");
            db.AddInParameter(dbCommand, "trackbackID", DbType.Int32, id);
            db.ExecuteNonQuery(dbCommand);
        }

        #endregion
    }
}
